﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace SchEdu.Framework.DataModel
{
    public class MachineList : List<SchEduDataSet.MachineRow>
    {
        public MachineList()
        {
        }

        public MachineList(MachineList machines)
            :base(machines)
        {
        }

        public MachineList(SchEduDataSet.MachineRow[] Machines)
        {
            foreach (SchEduDataSet.MachineRow Machine in Machines)
            {
                this.Add(Machine);
            }
        }

        public MachineList(SchEduDataSet.MachineDataTable MachineTable)
        {
            foreach (SchEduDataSet.MachineRow Machine in MachineTable)
            {
                this.Add(Machine);
            }
        }

        public SchEduDataSet.MachineRow FindByID(int MachineID)
        {
            foreach (SchEduDataSet.MachineRow Machine in this)
            {
                if (Machine.ID == MachineID)
                {
                    return Machine;
                }
            }
            return null;
        }

        public MachineList GetAvailableAt(int t)
        {
            MachineList machines = new MachineList();

            foreach (SchEduDataSet.MachineRow machine in this)
            {
                if (machine.AvailabilityDate <= t)
                {
                    machines.Add(machine);
                }
            }
            return machines;
        }


        public SchEduDataSet.MachineRow GetFirstAvailable()
        {
            SchEduDataSet.MachineRow firstMachine = null;
            foreach (SchEduDataSet.MachineRow machine in this)
            {
                if (firstMachine == null)
                {
                    firstMachine = machine;
                    continue;
                }
                if (machine.AvailabilityDate < firstMachine.AvailabilityDate)
                {
                    firstMachine = machine;
                }
            }
            return firstMachine;
        }

    }
}
